<?php
namespace AuctionCore\CarOwner;
use AuctionCore\System\ListBase;
use AuctionCore\CarResource\CarModel;
//
// +------------------------------------------------------------------------+
// | PHP Version 5.4                                                        |
// +------------------------------------------------------------------------+
// | Copyright (c) All rights reserved.                                     |
// +------------------------------------------------------------------------+
// | 世纪车来车往(北京）网络科技有限公司 版权所有！                         |
// | TEL:010-63732365  HOTLINE:400-6688-365  EMAIL:clcw@clcw.com.cn         |
// | $Revision: 1.0 $                                                       |
// +------------------------------------------------------------------------+
// | Author: songaimin@clcw.com.cn  Blog:http://blog.csdn.net/samxx8        |
// +------------------------------------------------------------------------+
//


/**
* "车主帐号"列表
* @author       爱民
*/
class OwnerUserList extends ListBase
{
    private $model = null;

    public function __construct() {
        $this->model = M('car_owner');
    }

    /**
     * 获取列表结果
     * @param   int $ev_page_num    每页条数
     * @param   int $page    页码
     * @param   array $params 参数
     * @return  array $list 列表
    */
    public function get($ev_page_num, $page, $params=array())
    {
        $page = (int)$page > 0 ? $page : 1 ;
        $ev_page_num = (int)$ev_page_num > 0 ? $ev_page_num : 10 ;
        $map = array();
        $map['aga.group_id'] = [['eq',1],['eq',3],'or'];
        if(intval($params['uid'])>0) {
            $map['u.uid'] = intval($params['uid']);
        }

        if(!empty($params['user_name'])) {
            $map['u.user_name'] = ['like',"%".trim($params['user_name'])."%"];
        }

        if(!empty($params['real_name'])) {
            $map['u.real_name'] = ['like',"%".trim($params['real_name'])."%"];
        }

        if(!empty($params['phone'])) {
            $map['u.pwd_mobile'] = trim($params['phone']);
        }
        //状态-1删除,0启用,1禁用
        if(intval($params['status'])>-1){
            $map['u.status'] = intval($params['status']);
        }else{
            $map['u.status'] = ['gt',-1];
        }
        //注册时间
        if($params['start_time']){
            $map['u.reg_date'] = array('egt',$params['start_time'] . ' 00:00:00');
        }
        if($params['end_time']){
            $map['u.reg_date'] = array('elt',$params['end_time'] . ' 23:59:59');
        }
        if($params['start_time'] && $params['end_time']){
            $map['u.reg_date'] = array(array('egt',$params['start_time'] . ' 00:00:00'),array('elt',$params['end_time'] . ' 23:59:59'));
        }
        $prefix = C("DB_PREFIX");
        $list = M("user")->alias("u")->field("u.*")
            ->join($prefix."auth_group_access as aga on aga.uid=u.uid")
            ->where($map)->page($page)->limit($ev_page_num)->order("u.reg_date DESC")->select();
        return $list;
    }

    /**
     * @param array $params
     * @return mixed
     */
    public function count($params=array())
    {
        $map = array();
        $map['aga.group_id'] = [['eq',1],['eq',3],'or'];
        if(intval($params['uid'])>0) {
            $map['u.uid'] = intval($params['uid']);
        }

        if(!empty($params['user_name'])) {
            $map['u.user_name'] = ['like',"%".trim($params['user_name'])."%"];
        }

        if(!empty($params['real_name'])) {
            $map['u.real_name'] = ['like',"%".trim($params['real_name'])."%"];
        }

        if(!empty($params['phone'])) {
            $map['u.pwd_mobile'] = trim($params['phone']);
        }
        //状态-1删除,0启用,1禁用
        if(intval($params['status'])>-1){
            $map['u.status'] = intval($params['status']);
        }else{
            $map['u.status'] = ['gt',-1];
        }
        //注册时间
        if($params['start_time']){
            $map['u.reg_date'] = array('egt',$params['start_time'] . ' 00:00:00');
        }
        if($params['end_time']){
            $map['u.reg_date'] = array('elt',$params['end_time'] . ' 23:59:59');
        }
        if($params['start_time'] && $params['end_time']){
            $map['u.reg_date'] = array(array('egt',$params['start_time'] . ' 00:00:00'),array('elt',$params['end_time'] . ' 23:59:59'));
        }
        $prefix = C("DB_PREFIX");
        $count =  M("user")->alias('u')->join($prefix."auth_group_access as aga on aga.uid=u.uid")->where($map)->count();
        return $count;
    }

}

?>